﻿using System;
using System.Collections;
using System.Collections.Generic;

using IBatisNet.DataAccess;

using AUV5.Model;
using AUV5.DAL;
using AUV5.DAL.Interface;
using AUV5.DAL.Dao;

namespace AUV5.BLL
{
    /// <summary>
    /// 功能：     GBAD业务逻辑实现
    /// 作者：     Wilson
    /// 日期：     2011/10/23
    /// 修改日期： 
    /// 修改人：
    /// 修改内容：
    /// </summary>
    public class GBADBLL
    {
        private static GBADBLL instance = new GBADBLL();
        private IDaoManager daoManager = ServiceConfig.Instance.DaoManager;
        private IGBADDao dao = null;

        private GBADBLL()
        {
            dao = GBADSqlMapDao.GetInstance();
        }

        public static GBADBLL GetInstance()
        {
            return instance;
        }

        /// <summary>
        /// 得到最大行数
        /// </summary>
        /// <returns></returns>
        public int GetMaxCounts()
        {
            try
            {
                //daoManager.BeginTransaction();

                int count = dao.GetMaxCounts();

                //daoManager.CommitTransaction();

                return count;
            }
            catch
            {
                //daoManager.RollBackTransaction();
                throw;
            }
        }

        /// <summary>
        /// 得到列表
        /// </summary>
        /// <returns></returns>
        public System.Collections.Generic.IList<GBAD> GetList()
        {
            try
            {
                //daoManager.BeginTransaction();

                System.Collections.Generic.IList<GBAD> list = dao.GetList();

                //daoManager.CommitTransaction();

                return list;
            }
            catch
            {
                //daoManager.RollBackTransaction();
                throw;
            }
        }

        /// <summary>
        /// 通过不同参数得到列表
        /// </summary>
        /// <param name="TopCounts"></param>
        /// <returns></returns>
        private System.Collections.Generic.IList<GBAD> GetListByParameters(object TopCounts, GBAD gbad)
        {
            try
            {
                //daoManager.BeginTransaction();

                Hashtable ht = new Hashtable();
                ht.Add("TopCounts", TopCounts);
                System.Collections.Generic.IList<GBAD> list = dao.GetListByParameters(ht);

                //daoManager.CommitTransaction();

                return list;
            }
            catch
            {
                //daoManager.RollBackTransaction();
                throw;
            }
        }


        /// <summary>
        /// 得到明细
        /// </summary>
        /// <param name="ADID"></param>
        /// <returns></returns>
        public GBAD GetDetail(System.String adid)
        {
            try
            {
                ///daoManager.BeginTransaction();

                return dao.GetDetail(adid);

                ///daoManager.CommitTransaction();
            }
            catch
            {
                ///daoManager.RollBackTransaction();
                throw;
            }
        }


        /// <summary>
        /// 新建
        /// </summary>
        /// <param name="gbad"></param>
        /// <returns></returns>
        public object Add(GBAD gbad)
        {
            //int id = GetId("SYS_UserInfoTemp");
            //sys_userinfotemp.UserID = id;

            try
            {
                ///daoManager.BeginTransaction();

                return dao.Add(gbad);
                ///daoManager.CommitTransaction();
            }
            catch
            {
                ///daoManager.RollBackTransaction();
                throw;
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="gbad"></param>
        /// <returns></returns>
        public int Update(GBAD gbad)
        {
            try
            {
                ///daoManager.BeginTransaction();

                return dao.Update(gbad);

                ///daoManager.CommitTransaction();
            }
            catch
            {
                ///daoManager.RollBackTransaction();
                throw;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="ADID"></param>
        /// <returns></returns>
        public int Delete(System.String adid)
        {
            try
            {
                ///daoManager.BeginTransaction();

                return dao.Delete(adid);

                ///daoManager.CommitTransaction();
            }
            catch
            {
                ///daoManager.RollBackTransaction();
                throw;
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="gbad"></param>
        /// <returns></returns>
        public int Delete(GBAD gbad)
        {
            try
            {
                ///daoManager.BeginTransaction();

                return dao.Delete(gbad);

                ///daoManager.CommitTransaction();
            }
            catch
            {
                ///daoManager.RollBackTransaction();
                throw;
            }
        }

        #region IGBADDao 成员

        /// <summary>
        /// 通过父编码得到集合
        /// </summary>
        /// <param name="parentCode"></param>
        /// <returns></returns>
        public IList<GBAD> GetListByADParentCode(string parentCode)
        {
            try
            {
                return dao.GetListByADParentCode(parentCode);
            }
            catch
            {

                throw;
            }
        }

        #endregion


        #region 通过Code获取名称

        /// <summary>
        /// 通过Code获取名称
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public string GetNameByCode(string code)
        {
            try
            {
                GBAD gbad=dao.GetDetailByCode(code);
                if (gbad != null)
                {
                    return gbad.ADName;
                }
                return "火星";
            }
            catch (Exception)
            {
                
                throw;
            }
        }

        #endregion

    }
}
